﻿using NW_WEB_Service.App.Interface;
using NW_WEB_Service.com.app.services;
using Service.src.NW.Model;
using Service.src.NW.Model.UserPageProject;
using System;
using System.Collections.Generic;

namespace NW_WEB_Service.App.Services
{
    public class ProjectService : DBService, ProjectInterface
    {

        public ProjectEntity Get(int Id)
        {
            ProjectEntity project = DBInstance.QueryOne<ProjectEntity>(P => P.Id == Id);
            return project;
        }

        public List<ProjectEntity> GetList()
        {
            List<ProjectEntity> list = DBInstance.QueryAll<ProjectEntity>();
            return list;
        }

        /// <summary>
        /// 发布项目
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ProjectEntity Released(int Id)
        {
            ProjectEntity project = Get(Id);
            if (project == null)
            {
                return null;
            }

            project.Released = !project.Released ;
            int r = DBInstance.Update<ProjectEntity>(project);
            return project;
        }

        public bool Delete(int Id)
        {
            ProjectEntity Project = new ProjectEntity();
            Project.Id = Id;
            return DBInstance.Delete<ProjectEntity>(Project);
        }

        public int Update(ProjectEntity Project)
        {
            int i = DBInstance.Update<ProjectEntity>(Project);
            return i;
        }

        public ProjectEntity Install(ProjectEntity Project)
        {
            Project = DBInstance.Install<ProjectEntity>(Project);
            return Project;
        }

        public ProjectEntity CopyProject(int ProjectId)
        {
            ProjectEntity Project = Get( ProjectId);
            ProjectEntity NewProject = new ProjectEntity();
            NewProject.Title = Project.Title +"-"+ DateTime.Now+"-副本";
            NewProject.Preview = Project.Preview;
            NewProject.Released = false;
            NewProject.Label = Project.Desc;
            NewProject.Desc = Project.Desc;
            NewProject = Install( NewProject);

            return NewProject;
        }

    }
}
